package com.msb.mall.producet.controller;

import java.util.Arrays;
import java.util.Map;

import com.msb.mall.producet.vo.SpuInfoVO;
import javafx.util.converter.ByteStringConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.msb.mall.producet.entity.SpuInfoEntity;
import com.msb.mall.producet.service.SpuInfoService;
import com.msb.common.utils.PageUtils;
import com.msb.common.utils.R;



/**
 * spu信息
 *
 * @author zhangjiajun
 * @email 1606516025@qq.com
 * @date 2025-05-08 21:19:06
 */
@RestController
@RequestMapping("/product/spuinfo")
public class SpuInfoController {
    @Autowired
    private SpuInfoService spuInfoService;

    /**
     * 上架商品
     * 查询出要存在es中的数据    存储到es中
     */
    @PostMapping("/{spuId}/up")
    public R spuUp(@PathVariable("spuId") Long spuId) {
        // 上架商品
        spuInfoService.spuUp(spuId);

        return R.ok();
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
//        PageUtils page = spuInfoService.queryPage(params);
        PageUtils page = spuInfoService.queryPageByCondition(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		SpuInfoEntity spuInfo = spuInfoService.getById(id);

        return R.ok().put("spuInfo", spuInfo);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody SpuInfoVO spuInfoVO){
//		spuInfoService.save(spuInfo);
        spuInfoService.saveSpuInfo(spuInfoVO);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SpuInfoEntity spuInfo){
		spuInfoService.updateById(spuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		spuInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
